package de.tum.in.elitese.wahlsys.controller;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import de.tum.in.elitese.wahlsys.common.DbService;
import de.tum.in.elitese.wahlsys.common.DbServiceFactrory;
import de.tum.in.elitese.wahlsys.common.KnownExecption;

/**
 * Controller for the performAnalysis.jsp<br /> It is an simple controller which
 * just triggers the analysis process
 * 
 * @author christoph
 * 
 */
public class PerformAnalysisController {
	/**
	 * Action Handler Method for performing the analysis of the election.
	 * 
	 * @return the navigation outcome
	 */
	public String performAnalysis() {
		DbService db = DbServiceFactrory.getInstance().createDbService();
		try {
			db.performElectionAnalysis();
		} catch (KnownExecption e) {
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
			e.printStackTrace();
			return null;
		}
		return "RESULT";
	}
}
